package com.own.util;

import java.util.HashMap;
import java.util.function.Function;
import java.util.function.Supplier;

/**
 * DefaultHashMap
 *
 * @author chenxueli
 * @date 2022-11-13 17:59:00
 */
public class DefaultHashMap<K, V> extends HashMap<K, V> {

    /**
     * 默认的函数信息
     */
    private final Function<K, V> function;

    public DefaultHashMap(Supplier<V> supplier) {
        super();
        this.function = k -> supplier.get();
    }

    @Override
    @SuppressWarnings("unchecked")
    public V get(Object key) {
        return super.computeIfAbsent((K) key, this.function);
    }

}
